package com.java.web.manageweb.controller.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.java.manage.pojo.TbItemDesc;
import com.java.manage.service.TbItemDescService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @ClassName ApiItemDescController
 * @Description 商品描述api
 * @Author Trigger Wu
 * @Date 2018/9/1315:06
 * @Version 1.0
 **/
@RequestMapping("/rest/api/item/desc")
@Controller
public class ApiItemDescController {
    @Autowired
    private TbItemDescService itemDescService;
    /*
     *  根据id查询商品描述
     *
     * @author Tigger Wu
     * @date 2018/9/18 9:17
     * @param [itemId]
     * @return ResponseEntity<ItemDesc>
     */
    @RequestMapping(value = "{itemId}", method = RequestMethod.GET)
    public ResponseEntity<TbItemDesc> queryById(@PathVariable("itemId") Long itemId) {
        try {
            EntityWrapper wrapper = new EntityWrapper();
            wrapper.where("item_id={0}",itemId);
            TbItemDesc itemDesc = itemDescService.selectOne(wrapper);
            if (null == itemDesc) {
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
            }
            return ResponseEntity.ok(itemDesc);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
